@echo off

rem Copyright 2010(c) Lasse Liehu

set PATH=%PATH%;%CD%

If [%1]==[--help] GOTO HELP
If [%1]==[] GOTO SKIPDIRCHANGING
cd %1
:SKIPDIRCHANGING

echo Google Reader Notifier Qt dir cleaner for Windows packaging
echo -----------------------------------------------------------
echo Please see --help for how to call this script
echo Please make sure you have a full backup!
echo Otherwise you WILL lose data!
echo If this operation fails, the contents won't be in a clean state.

rem ### Here we remind the user if it seems like he/she has forgot to build the source
set not_built_warn=0
If not exist settings_cleaner\debug set /a not_built_warn=%not_built_warn%+1
If not exist settins_cleaner\release set /a not_built_warn=%not_built_warn%+1
If %not_built_warn% GEQ 2 echo WARNING Have you forgot to build directory `settings_cleaner'?
set not_built_warn=0
If not exist src\debug set /a not_built_warn=%not_built_warn%+1
If not exist src\release set /a not_built_warn=%not_built_warn%+1
If %not_built_warn% GEQ 2 echo WARNING Have you forgot to build directory `src'?

echo Press Ctrl-C to cancel or any key to continue
pause

If not exist google-reader-notifier-qt.pro goto WRONG_WORKING_DIR

echo === Removing source code from src\integration\
cd src\integration
del *.cpp *.h *.ui *.pro *.qrc Makefile* object_script.*.Debug object_script.*.Release *.rc
cd ..\..
rmdir src\integration

echo === Removing source code from src\
cd src
del /s /q debug
rmdir debug
del /s /q release
rmdir release
del *.cpp *.h *.ui *.pro *.qrc Makefile* object_script.*.Debug object_script.*.Release *.rc
cd ..
rmdir src

echo === Removing source code from settings_cleaner\
cd settings_cleaner
del /s /q debug
rmdir debug
del /s /q release
rmdir release
del *.cpp *.h *.ui *.pro *.qrc Makefile* object_script.*.Debug object_script.*.Release *.rc
cd ..
rmdir settings_cleaner


If exist bin\debug echo === Deleting everything inside bin\debug\, and the directory itself
If exist bin\debug del /s /q bin\debug\*.*
If exist bin\debug rmdir bin\debug

echo === Creating directories install_dir\
mkdir install_dir\

echo === Moving binaries from bin\release\ to install_dir\bin\
mkdir install_dir\bin
move bin\release\*.* install_dir\bin

echo === Deleting the directory bin\ as useless
rmdir bin\release
rmdir bin

echo === Copying important DLLs to install_dir\bin\
copy %QTDIR%\bin\QtCore4.dll install_dir\bin\
copy %QTDIR%\bin\QtGui4.dll install_dir\bin\
copy %QTDIR%\bin\QtNetwork4.dll install_dir\bin\
copy %QTDIR%\bin\QtSvg4.dll install_dir\bin\
copy %QTDIR%\bin\QtXml4.dll install_dir\bin\
copy %QTDIR%\bin\mingwm10.dll install_dir\bin\
copy %QTDIR%\bin\libgcc_s_dw2-1.dll install_dir\bin\

echo === Deleting unnecessary files from data\
del data\*.desktop
del data\greader_notifier_widgetbg.svg
del data\icons\application\*.png
del data\icons\installer\*.png
del data\icons\installer\*.svg
del "data\icons\old design\*.*"
rmdir "data\icons\old design"
del data\icons\symbols\*.*
rmdir data\icons\symbols
del data\icons\uninstaller\*.png
del data\icons\uninstaller\*.svg

rem We don't need nor want icons to be installed as files in install_dir\data
echo === Moving data\ to install_dir\data\
mkdir install_dir\data
move data\*.* install_dir\data
rmdir data

echo === Deleting unnecessary files from the base directory
del *.pro
del *.pro.user
del README.txt
del Makefile
del Doxyfile

echo === Renaming important text files in the base directory
rename COPYING COPYING.txt
rename AUTHORS AUTHORS.txt
rename "README for binary Windows version.txt" README.txt

echo === Converting important text files to Windows-style newlines
EOL-formatter.exe -w README.txt COPYING.txt AUTHORS.txt

echo === Copying important text files to install_dir\
move COPYING.txt install_dir\
move AUTHORS.txt install_dir\
move README.txt install_dir\

echo === Done. Please check that everything's alright.
echo === Press any key to exit. Bye.
pause
goto :EOF

:WRONG_WORKING_DIR
echo The working directory doesn't contain google-reader-notifier-qt.pro.
echo Please check that you run this script in the correct directory.
echo Press any key to exit. See you soon.
pause
goto :EOF

:HELP
echo Usage: "cleanup for win packaging.bat" [directory]
echo        where directory is the directory where Google Reader Notifier Qt source is
echo You can also pass --help as the first parameter to get this help text.
